package com.ggj2013.hbh.utils;

import com.eclecticdesignstudio.spritesheet.SpriteSheet;
import com.eclecticdesignstudio.spritesheet.importers.SpriteLoq;
//import com.eclecticdesignstudio.spritesheet.importers.AnimoImporter;
import com.eclecticdesignstudio.spritesheet.AnimatedSprite;
import nme.Assets;
import nme.display.Bitmap;
import nme.Lib;
import nme.system.Capabilities;
import nme.text.Font;

/**
 * @author Jonathan Moriarty
 */
class Tools 
{
	inline public static var ASSET_PATH:String = "Assets/flash";
	inline public static var BITMAP_EXTENSION:String = ".png";
	inline public static var SPRITE_SHEET_EXTENSION:String = ".xml";
	inline public static var XML_EXTENSION:String = ".xml";
	inline public static var FONT_EXTENSION:String = ".ttf";
	
	public static function loadBitmap( l_name:String ):Bitmap
	{
		return new Bitmap( Assets.getBitmapData( ASSET_PATH + "/" + l_name + BITMAP_EXTENSION ) );
	}
	
	public static function loadSpriteSheet( l_name:String ):SpriteSheet
	{
		return SpriteLoq.parse( ApplicationMain.getAsset( ASSET_PATH + "/" + l_name + SPRITE_SHEET_EXTENSION ), ASSET_PATH );
	}
	
	public static function loadXML( l_name:String ):haxe.xml.Fast
	{
		var l_base:String = Assets.getText( ASSET_PATH + "/" + l_name + FONT_EXTENSION );
		var l_xml = Xml.parse( l_base );	
		return new haxe.xml.Fast( l_xml.firstElement() );	
	}
	
	public static function loadFont( l_name:String ):Font
	{
		return Assets.getFont( ASSET_PATH + "/" + l_name + FONT_EXTENSION );
	}	
	
	public static function trace( l_message:String ):Void
	{
		#if debug
			trace( l_message );
		#end
	}
	
	//--------------
	// Calculations 
	//--------------
	
	/**
	 * Calculates a random Int between the two specified values, including the second but excluding the first.
	 */
	public static function randomInt( high:Int, low:Int )
	{
		return Math.floor( Math.random() * ( high - low ) ) + low; 
	}
	
	/**
	 * Calculates a random Float between the two specified values, including the second but excluding the first.
	 */
	public static function randomFloat( high:Float, low:Float ):Float
	{
		return ( Math.random() * ( high - low ) ) + low; 
	}

}
